package crivia.ecp.carry.tableString;

import crivia.ecp.common.ECR;

public class TableColumn {
	
	protected String name;
	
	protected String width;
	
	protected String dataKey;
	
	protected String orderKey;
	
	protected TableColumnLink columnLink;
	
	protected TableColumnMethod columnMethod;
	
	protected boolean enable = true;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getDataKey() {
		return dataKey;
	}
	
	public void setDataKey(String dataKey) {
		this.dataKey = dataKey;
	}

	public String getOrderKey() {
		return orderKey;
	}

	public void setOrderKey(String orderKey) {
		this.orderKey = orderKey;
	}

	public TableColumnLink getColumnLink() {
		return columnLink;
	}

	public void setColumnLink(TableColumnLink columnLink) {
		this.columnLink = columnLink;
	}
	
	public TableColumnMethod getColumnMethod() {
		return columnMethod;
	}

	public void setColumnMethod(TableColumnMethod columnMethod) {
		this.columnMethod = columnMethod;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public TableColumn(String name, String width, String dataKey,
			String orderKey, TableColumnLink columnLink) {
		super();
		this.name = name;
		this.width = width;
		this.dataKey = dataKey;
		this.orderKey = orderKey;
		this.columnLink = columnLink;
	}

	public TableColumn(String name, String width, String dataKey,
			String orderKey) {
		super();
		this.name = name;
		this.width = width;
		this.dataKey = dataKey;
		this.orderKey = orderKey;
	}

	public TableColumn(String name, String width, String key) {
		super();
		this.name = name;
		this.width = width;
		this.dataKey = key;
		this.orderKey = key;
	}

	public TableColumn(String name, String width, TableColumnMethod columnMethod) {
		super();
		this.name = name;
		this.width = width;
		this.columnMethod = columnMethod;
	}

	@Override
	public String toString() {
		StringBuilder tStr = new StringBuilder("<col text=");
		tStr.append(TableString.toAttr(name));
		tStr.append(" width=");
		tStr.append(TableString.toAttr(width));
		if (ECR.hasCondition(orderKey)){
			tStr.append(" orderkey=");
			tStr.append(TableString.toAttr(orderKey));
		}
		if (null != dataKey){
			tStr.append(" column=");
			tStr.append(TableString.toAttr(dataKey));
		}
		if (null != columnLink){
			tStr.append(" href=");
			tStr.append(TableString.toAttr(columnLink.getUrl()));
			tStr.append(" target=");
			tStr.append(TableString.toAttr(columnLink.getTarget()));
			tStr.append(" linkkey=");
			tStr.append(TableString.toAttr(columnLink.getParamKey()));
			tStr.append(" linkvaluecolumn=");
			tStr.append(TableString.toAttr(columnLink.getParamValue()));
		}
		if (null != columnMethod){
			tStr.append(" transmethod=");
			tStr.append(TableString.toAttr(columnMethod.getType().getName() + "." + columnMethod.getMethod()));
			tStr.append(" otherpara=");
			tStr.append(TableString.toAttr(columnMethod.getParam()));
		}
		tStr.append(" />");
		return tStr.toString();
	}

}
